<html>
<head>  
	<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"> 
	<script type="text/javascript" src="sylvester.js"></script> 
	<script type="text/javascript" src="glUtils.js"></script>
	<script type="text/javascript" src="binaryReader.js"></script>
		<script type="text/javascript" src="loader.js"></script>
	<script type="text/javascript" src="renderer.js"></script>
	<META HTTP-EQUIV="Keywords" CONTENT="WebGL, javascript, html5, canvas, loader, parser, 3D, model, GPL">
</head>

<script id="shader-fs" type="x-shader/x-fragment">
  #ifdef GL_ES
  precision highp float;
  #endif

  varying vec2 vTextureCoord;
  varying vec3 vLightWeighting;

  uniform bool uUseTextures;
  uniform sampler2D uSampler;

  void main(void) {
     vec4 fragmentColor;
	if (uUseTextures) 
     		fragmentColor = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t));
    	else 
     		 fragmentColor = vec4(1.0, 1.0, 1.0, 1.0);
     gl_FragColor = vec4(fragmentColor.rgb*vLightWeighting, fragmentColor.a);
	//gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
  }
</script>

<script id="shader-vs" type="x-shader/x-vertex">
  attribute vec3 aVertexPosition;
  attribute vec3 aNormals;
  attribute vec2 aTextureCoord;

  uniform mat4 uMVMatrix;
  uniform mat4 uPMatrix;
  uniform mat4 uNMatrix;

  uniform vec3 uAmbiantLight;
  uniform vec3 uDirectionnalLight;

  varying vec2 vTextureCoord;
  varying vec3 vLightWeighting;

  void main(void) {
    
    vTextureCoord = aTextureCoord;
    vec4 transformedNormal = uNMatrix * vec4(aNormals, 1.0);
      vLightWeighting = uAmbiantLight+uDirectionnalLight*max(dot(transformedNormal.xyz, vec3(1.0,1.0, 1.0)), 0.0);
	// vLightWeighting = vec3(1,1,1);
	gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);
  }
</script>



<body onload="webGLStart();">

<h1>Blender Loader Demo</h1>
This is a a webGL demo of a loader of blender files. Altough I uploaded it, this project isn't even in alpha stage. For the moment, the code is poorly commented. This demo has only been tested with the beta of Firefox 4.0 and chrome 7.0. You will probably need to download a beta of a recent browser to see this demo: <a href="http://khronos.org/webgl/wiki/Getting_a_WebGL_Implementation">getting a WebGL Implementation.</a> If you need information about this demo, you can contact me : nicolas dot bonnel at gmail dot com. The code is licenced under GNU GPL 3. Feel free to reuse the code, credits would be appreciated.<br>

Models available :
<ul>
<li>thing</li>
<li>zombie</li>
<li>mago-cc</li>
<li>rf</li>
<li>Sinbad</li>
</ul>

<table>
<tr><td>Model's URL </td><td><input size=60 type=text id="modelURL" value="http://www-valoria.univ-ubs.fr/Nicolas.Bonnel/3D/models/thing.blend"></td><td><form action="javascript:load_binary_resource()"><input type="submit" value="load"></form>
</td></tr>
<tr><td colspan=2><canvas id=".blend viewer" style="border: none;" width="640" height="480"></canvas></td>
<td><div id="console"></div></td></tr>
</table>
<h2>Links</h2>
I didn't know anything about javascript and webGL before making this demo. Here are some useful links I found.<br> 
<a href="http://learningwebgl.com/blog/">My webGL knowledge come from here, some portion of code too ...</a><br>
<a href="http://opengameart.org/">All the blender models come from here, great site !</a><br>
<a href="http://www.atmind.nl/blender/mystery_ot_blend.html">The structure of a blender file</a><br>
<a href="http://jsfromhell.com/classes/binary-parser">The javascript binary parser used to decode integer and floats</a><br>

<h2>Todo</h2>
There are still a lot of things to do, but i spend most on my free time on <a href="world/loader.html">another project</a> now.
<ul>
<li>Clean the code, comment it, ...</li>
<li>Implement mouse movement (turning around the model, zoom)</li>
<li>Implement skeleton animation</li>
<li>Add some keywords</li>
<li>Upload more models, add a list/menu to select them</li>
<li>Other improvement of the 3D engine (normal mapping, clipmap, ...) </li>
<li>...</li>
</ul>
</body>
</html>
